package com.bw.module_home.repair.model

import com.bw.lib_common.entity.Res
import com.bw.module_home.home.model.HomeNetModule
import com.bw.module_home.repair.api.RepairApiService
import dagger.hilt.android.scopes.ActivityScoped
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

//class RepairRepository:BaseRepository<RepairApiService>() {
//    override fun createApiServer(): RepairApiService =OkHttpClientManager.retrofitInstance.create(RepairApiService::class.java)
//
//
//    suspend fun getRepairList():Res<RepairEntity> = apiService.getRepairOrders()
//    suspend fun addRepair(addRepairEntity: AddRepairEntity):Res<RepairEntityItem> = apiService.addRepairOrder(addRepairEntity)
//    suspend fun deleteRepair(id:Int):Res<Boolean> =apiService.deleteRepairOrder(id)
//    suspend fun getRepairOrderByNumber(orderNumber:String):Res<RepairEntityItem> =apiService.getRepairOrderByOrderNumber(orderNumber)
//    suspend fun getRepairOrderByName(name:String):Res<RepairEntity> =apiService.getRepairOrderByName(name)
//}
class RepairRepository @Inject constructor() {
    @Inject
    @RepairModule.CommonHomeApi
    lateinit var api:RepairApiService

    fun getRepairList(): Flow<Res<RepairEntity>> = flow {
        emit(api.getRepairOrders())
    }.flowOn(Dispatchers.IO)

    fun addRepair(addRepairEntity: AddRepairEntity): Flow<Res<RepairEntityItem>> = flow {
        emit(api.addRepairOrder(addRepairEntity))
    }.flowOn(Dispatchers.IO)

    fun deleteRepair(id: Int): Flow<Res<Boolean>> = flow {
        emit(api.deleteRepairOrder(id))
    }.flowOn(Dispatchers.IO)

    fun getRepairOrderByNumber(orderNumber: String): Flow<Res<RepairEntityItem>> = flow {
        emit(api.getRepairOrderByOrderNumber(orderNumber))
    }.flowOn(Dispatchers.IO)

    fun getRepairOrderByName(name: String): Flow<Res<RepairEntity>> = flow {
        emit(api.getRepairOrderByName(name))
    }.flowOn(Dispatchers.IO)
}